package test_modele;

import static org.junit.Assert.*;

import java.awt.List;
import java.io.IOException;
import java.util.ArrayList;

import modele.Album;
import modele.Bdtheque;
import modele.CollectionAlbums;
import modele.ListModelAlbums;
import modele.Traitement;

import org.junit.Before;
import org.junit.Test;

public class TTraitement {
	Traitement traitement;
	Bdtheque bdt;
	Album a,b,c;
	CollectionAlbums collection;
	ArrayList<CollectionAlbums> listeCollection;
	
	@Before
	public void setUp() throws IOException{
		traitement=new Traitement(bdt);
		bdt=new Bdtheque();
		collection=new CollectionAlbums(bdt, "collection");
		listeCollection=new ArrayList<CollectionAlbums>();
		a = new Album("Tintin au Tibet", "Hergé", "editeur", "aventure", "Tintin", "synopsis", 5, " "," ");
		b= new Album("Nitnit au Tebit","Géher",null,"l'Aaaaaventura","Nitnit","resumé", 6, "abcd"," ");
		c=new Album("Tintin au Tibet", "Hergé", "editeur", "aventure", "Tintin", "synopsis", 0, null,null);
		collection.add(a);
		//collection.add(b);
		//collection.add(c);
		listeCollection.add(collection);
		bdt.setListeCollections(listeCollection);
	}
	
	@Test
	public void testAjouterAlbumBDtheque(){
		assertTrue(traitement.ajouterAlbumBdtheque("Tintin au Tibet", "Hergé", "editeur", "aventure", "Tintin", "synopsis", 5, " "," "));
	}
	
	@Test
	public void testAjouterAlbumCollection(){
		traitement.ajouterAlbumCollection(0, 0);
		assertTrue(traitement.getBdt().getListeCollections().get(0).contains(a));	
	}
	
	@Test
	public void testAjouterCommentaire(){
		traitement.ajouterCommentaire(a, "comment");
		assertEquals("comment", a.getCommentaire());
	}
	@Test
	public void testSetNote(){
		traitement.setNote(a, 42);
		assertEquals(42, a.getNote());
	}
	
	@Test
	public void testSetGenre(){
		traitement.setGenre(a, "genre");
		assertEquals("genre", a.getGenre());
	}
	
	@Test
	public void testCreerCollection(){
		traitement.creerCollection("nouvelle");
		ArrayList<CollectionAlbums>temp=new ArrayList<CollectionAlbums>();
		CollectionAlbums nouvelle=new CollectionAlbums(bdt, "nouvelle");
		temp.add(collection);
		temp.add(nouvelle);
		assertEquals(temp, bdt.getCollections());
	}
	
	@Test
	public void testRechercherAll(){
		ArrayList<Album> liste=new ArrayList<Album>();
		ListModelAlbums<Album> temp=new ListModelAlbums<Album>(liste);
		liste.add(a);
		assertEquals(temp, traitement.rechercheAll("tintin"));
	}
	
	@Test
	public void testRechercheAvancee(){
		ArrayList<Album> liste=new ArrayList<Album>();
		ListModelAlbums<Album> temp=new ListModelAlbums<Album>(liste);
		liste.add(a);
		assertEquals(temp, traitement.rechercheAvancee("Tintin au Tibet", "Hergé", "editeur", "aventure", "Tintin", "synopsis"));
	}
	
	@Test
	public void testSupprimerCollection(){
		bdt.addCollection(new CollectionAlbums(bdt, "nom"));
		traitement.supprimerCollection(1);
		assertEquals(1, bdt.getSize());
	}
	
	@Test
	public void testSupprimerAlbumDansCollection(){
		traitement.supprimerAlbumDansCollection(0, 0);
		assertFalse(collection.contains(a));
	}
	
	@Test
	public void testModifierAlbum(){
		assertTrue(traitement.modifierAlbum(a, "titre", " ", " ", " ", " ", " ", 0 ," "));
		Album temp=new Album("titre", " ", " ", " ", " ", " ", 0," ", " ");
		assertEquals(temp,a);
	}
	
	@Test
	public void testGetAlbums(){
		CollectionAlbums temp=new CollectionAlbums(bdt, " ");
		temp=collection;
		assertEquals(temp,traitement.getAlbums());
	}
	
	@Test
	public void testGetCollections() throws IOException{
		Bdtheque temp=new Bdtheque();
		temp=bdt;
		assertEquals(temp,traitement.getCollections());
	}
	
	@Test
	public void testGetListCollection(){
		ArrayList<CollectionAlbums> temp=new ArrayList<CollectionAlbums>();
		temp.add(collection);
		assertEquals(temp, traitement.getListCollections());
	}
	
	@Test
	public void testSetNomCollection(){
		traitement.setNomCollection(0, " ");
		assertEquals(" ", collection.getNom());
	}
	
	@Test
	public void testGetAndSetBdt() throws IOException{
		Bdtheque temp=new Bdtheque();
		temp=bdt;
		traitement.setBdt(temp);
		assertEquals(bdt, traitement.getBdt());
	}
}


















